package com.sayp.netdisk.controller;

import com.sayp.netdisk.pojo.File;
import com.sayp.netdisk.pojo.User;
import com.sayp.netdisk.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("file")
public class FileController {
    @Autowired
    private FileService fileService;
    @Autowired
    private UserController userController;

    /**
     * 上传文件
     * @param files
     * @param parentId
     * @return
     */
    @PostMapping("/upload/{parentId}")
    public boolean upload(MultipartFile[] files, String dirName, @PathVariable("parentId") int parentId, HttpSession session){
        User user = userController.getUserInfo(session);
        if(user==null || (files==null && dirName==null))return false;
        if(files!=null)return fileService.createFiles(files, parentId, user.getUid());
        else return fileService.createDir(dirName,parentId, user.getUid());
    }


//    /**
//     * 构建压缩包
//     * @param fids 需要构建的文件id
//     * @return 压缩包名
//     */
//    @GetMapping("/buildZip")
//    public String buildZip(int[] fids){
//        String zipName = fileService.buildZip(fids);
//        if(zipName==null)
//            return "";
//        return zipName;
//    }


}
